package gw.com.android.ui.quote2;

import android.animation.AnimatorSet;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.view.ViewPager;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.flyco.tablayout.SlidingTabLayout;
import com.gwtsz.android.rxbus.RxBus;
import com.gwtsz.gts2.hx.R;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import gw.com.android.app.ActivityManager;
import gw.com.android.app.AppContances;
import gw.com.android.app.AppMain;
import gw.com.android.app.GTConfig;
import gw.com.android.model.ConfigType;
import gw.com.android.model.ConfigTypesDeal;
import gw.com.android.model.ConfigUtil;
import gw.com.android.model.DataManager;
import gw.com.android.presenter.AdsConfigPresenter;
import gw.com.android.presenter.AdsData;
import gw.com.android.presenter.NoviceWelfarePresenter;
import gw.com.android.presenter.PresenterImpl;
import gw.com.android.presenter.SwitchAccountPresenter;
import gw.com.android.presenter.http.HttpCallback;
import gw.com.android.terminal.AppTerminal;
import gw.com.android.ui.BaseActivity;
import gw.com.android.ui.InspectNetworkActivity;
import gw.com.android.ui.MainActivity;
import gw.com.android.ui.dialog.PopupConfirmDialog;
import gw.com.android.ui.quote2.view.ServerErrorView;
import gw.com.android.ui.views.CommonTitleBar;
import gw.com.android.utils.OpenApi;
import gw.com.android.utils.PackStatis;
import gw.com.android.utils.ServerConnnectUtil;
import gw.com.android.utils.TimeJudgeUtil;
import gw.com.jni.library.terminal.GTSConst;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.annotations.NonNull;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;
import www.com.library.app.Logger;
import www.com.library.app.PushMsgTabFragment;
import www.com.library.model.DataItemDetail;
import www.com.library.model.DataItemResult;
import www.com.library.util.CommonUtils;
import www.com.library.util.DeviceUtil;
import www.com.library.util.NetworkMonitor;
import www.com.library.view.BtnClickListener;
import www.com.library.view.LoadingProgress;

/**
 * 行情模块界面-自选产品；
 * <p>
 * 2018年11月29日 10:04:12起，对此类进行改造，增加商品类型分类;
 */
public class NewQuoteFragment extends PushMsgTabFragment implements PresenterImpl {

    //主载体
    @BindView(R.id.sl_product_type)
    SlidingTabLayout mProductTypeTab;//滑动的头部
    @BindView(R.id.quote_product_pager)
    ViewPager mProductPager;//滑动的内容部分
    ProductTypeAdapter mProductTypeAdapter;//viewpager适配器

    @BindView(R.id.main_tab_title_bar)
    CommonTitleBar mTitleBar;
    /**
     * 数据加载圈
     */
    @BindView(R.id.loading_progress_view)
    LoadingProgress mProgress;
    @BindView(R.id.net_error_view)
    TextView mNetErrorTopView;
    @BindView(R.id.server_error_view)
    View mServerErrorTopView;
    @BindView(R.id.net_error_layout)
    TextView mNetErrorLayout;
    @BindView(R.id.severerror_layout)
    ServerErrorView mServerErrorView;
    @BindView(R.id.quote_bottom_bar)
    View mLoginLayout;
    @BindView(R.id.quote_bottom_ad)
    TextView mTvAdsBottom;
    @BindView(R.id.error_top_layout)
    LinearLayout mErrorTopLayout;


    public static final String CHANGE_QUOTE_EVENT = "changeQuoteEvent";
    private PushMsgTabFragment mCurrentFragment = null; // 当前显示的fragment

    private SwitchAccountPresenter mSwitchPresenter;

    private boolean isRiseType = false;//切换

    public static String mTypeName = "自选";//由于一进去，默认显示的自选

    @Override
    public void onAccountNotify() {
        Log.d("onAccountNotify", "本类hashCode是：" + this.toString() + ";收到账户变更的消息");
        super.onAccountNotify();
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        super.onCreateView(inflater, container, savedInstanceState);
        return mRootView;
    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_main_new_quote;
    }

    @Override
    protected void initLayoutView() {
        ButterKnife.bind(this, mRootView);
        BaseActivity activity = (BaseActivity) getActivity();
        if (null != activity) {
            activity.setTransparentBar(false);
        }
        // 抢占点击事件，以便下层界面不可点击
        mProgress.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
            }
        });
        onProgressVisible(true);
        isRiseType = GTConfig.instance().getBooleanValue(GTConfig.PREF_RISE_QUOTE, false);

        //如果当前登录的用户是游客，那么，显示标题为"自选"
        if (ifGuest()) {
            mTitleBar.setAppTitle("自选");
        } else {//否则，显示为行情
            mTitleBar.setAppTitle(R.string.main_menu_item_quote);
        }

        dispatchEditBtnBySelfTick();

        if (isRiseType) {
            mTitleBar.setRightIcon(R.mipmap.a_nav_quote_bs);
        } else {
            mTitleBar.setRightIcon(R.mipmap.a_nav_quote_pa);
        }
        mLoginLayout.setVisibility(View.GONE);

        mTitleBar.setBtnClickListener(new BtnClickListener() {

            @Override
            public void onBtnClick(int viewID) {
                switch (viewID) {
                    case R.id.title_left_text:
                        ActivityManager.showEditOptionalActivity(getActivity(), AppMain.getAppString(R.string.quote_title_edit_product));
                        break;
                    case R.id.title_right_icon:
                        if (isRiseType) {
                            mTitleBar.setRightIcon(R.mipmap.a_nav_quote_pa);
                        } else {
                            mTitleBar.setRightIcon(R.mipmap.a_nav_quote_bs);
                        }
                        isRiseType = !isRiseType;
                        QuoteInsideFragment.mIsRiseType = isRiseType;
                        RxBus.getInstance().post(GTSConst.REPLY_SWITCH_TABLE_HEADER + "", isRiseType);//发消息,告诉所有的QuoteInsideFragment更换表头
                        GTConfig.instance().setBooleanValue(GTConfig.PREF_RISE_QUOTE, isRiseType);
                        break;
                }

            }
        });
        setClickView();
        mErrorTopLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                getContext().startActivity(new Intent(getContext(), InspectNetworkActivity.class));
            }
        });
    }

    private void requestCpsSwitch() {//加个特殊逻辑：发送请求去访问CPS接口，看看开关是否打开，如果打开，就显示数字货币；关闭，则不显示数字货币;
        mProgress.setViewVisibility(View.VISIBLE);
        OpenApi.requestDigitalCurrency(new HttpCallback<Boolean>() {
            @Override
            public void onSuccess(Boolean result) {
                mProgress.setViewVisibility(View.GONE);
                loadQuoteTable(result);
            }

            @Override
            public void onFailure(Exception e) {
                mProgress.setViewVisibility(View.GONE);
                loadQuoteTable(true);//请求失败，还是显示
            }
        });
    }

    /**
     * 在规定时间之内自动切换到数字货币
     */
    public void switchTab() {
        boolean ifInside = TimeJudgeUtil.ifTimeInside(getTimeRange());
        if (ifInside) {
            if (mIfCpsOpen) {//如果cpsF开关是打开的(因为打开了cps开关，才会有 这个数字货币)
                if (mProductPager != null) {
                    mTypesDeal = new ConfigTypesDeal();
                    mTabTitles = mTypesDeal.getQuoteTypeList();//那就取全部类型
                    //并且找到数字货币所在的位置
                    int btTypePosition = 0;
                    for (int i = 0; i < mTabTitles.getDataCount(); i++) {
                        if ("数字货币".equals(mTabTitles.getItem(i).getString(ConfigType.CONFIG_TYPE_TITLE_TAG))) {
                            btTypePosition = i + 1;//这里+1.是因为，在实际UI上，取到配置的产品list之后，我在第一个位置强行加了一个“自选”，具体参考ProductTypeAdapter.java Row-52起.
                            break;
                        }
                    }
                    mProductTypeTab.setCurrentTab(btTypePosition);//那么就尝试切换到“数字货币”
                }
            }
        } else {
            Log.d("ifTimeInside", "不在规定时间之内，不切换到数字货币");
        }
    }

    private DataItemResult mTabTitles;
    private ConfigTypesDeal mTypesDeal;

    private List<String[]> getTimeRange() {
        List<String[]> range = new ArrayList<>();
        JSONArray ja = ConfigUtil.instance().getDigitalCurrencyTimeRange();//这个range要从配置文件中读取
        if (ja != null)
            for (int i = 0; i < ja.length(); i++) {
                try {
                    JSONObject jab = (JSONObject) ja.get(i);
                    String dayOfWeek = (String) jab.get("dayOfWeek");
                    String startTime = (String) jab.get("startTime");
                    String endTime = (String) jab.get("endTime");

                    range.add(new String[]{dayOfWeek, startTime, endTime});
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        return range;
    }

    private boolean mIfCpsOpen;

    /**
     * 加载行情tabLayout数据
     *
     * @param ifCpsOpen
     */
    private void loadQuoteTable(final boolean ifCpsOpen) {
        AppMain.getApp().getHandler().post(new Runnable() {
            @Override
            public void run() {
                if (null == mProductTypeAdapter) {
                    mProductTypeAdapter = new ProductTypeAdapter(getChildFragmentManager(), ifGuest(), ifCpsOpen);
                    mProductPager.setAdapter(mProductTypeAdapter);
                    mProductPager.setOffscreenPageLimit(0);
                    mProductTypeTab.setViewPager(mProductPager);//viewPager不能重复set,所以我加了一个判断
                    mProductPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
                        @Override
                        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

                        }

                        @Override
                        public void onPageSelected(int position) {
                            dispatchEditBtnByPosition(position);
                            //这里切换的时候可以拿到当前产品的名字
                            mTypeName = (String) mProductPager.getAdapter().getPageTitle(position);
                        }

                        @Override
                        public void onPageScrollStateChanged(int state) {

                        }
                    });
                }
                mIfCpsOpen = ifCpsOpen;
                switchTab();
            }
        });

    }

    private boolean ifGuest() {
        return GTConfig.instance().getAccountType() == GTConfig.ACC_TYPE_GUEST;
    }

    private int mCurrentPosition;

    private void dispatchEditBtnByPosition(int position) {//判断当前是不是自选，如果不是，就不显示编辑按钮
        mCurrentPosition = position;
        if (position == 0) {
            dispatchEditBtnBySelfTick();
        } else {
            mTitleBar.setLeftText("");
        }

    }

    private void dispatchEditBtnBySelfTick() {
        if (DataManager.instance().getSelfTickList().getDataCount() > 0)//判断自选列表是不是空，不是空，就显示这个titleBar
            mTitleBar.setLeftText(R.string.main_menu_item_edit_product);
        else
            mTitleBar.setLeftText("");
    }

    @Override
    public void onResume() {
        super.onResume();
        dispatchEditBtnByPosition(mCurrentPosition);
    }

    @Override
    protected void initViewData() {
        AdsData bottomAd = AdsConfigPresenter.getInstance().getAd(AdsConfigPresenter.TYPE_HOME_BOTTOM);
        dealBottomAdsData(bottomAd, mTvAdsBottom);
    }

    /**
     * 底部开护栏广告
     */
    public void dealBottomAdsData(AdsData bottomAd, TextView textView) {
        if (bottomAd == null || bottomAd.adPics == null || bottomAd.adPics.isEmpty()) {
            return;
        }
        final AdsData.PicData picData = bottomAd.adPics.get(0);
        if (picData == null || TextUtils.isEmpty(picData.title)) {
            return;
        }
        textView.setText(picData.title);
    }

    @Override
    public void registerRxBus() {
        Disposable netRegister = RxBus.getInstance().registertoObservableSticky(GTSConst.REPLY_NETWORK_STATE + "", Boolean.class).observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<Boolean>() {

                    @Override
                    public void accept(@NonNull Boolean isNetWork) throws Exception {
                        Logger.e("NewQuoteFragment isNetWork is " + isNetWork);
                        if (isNetWork) {
                            mNetErrorTopView.setVisibility(View.GONE);
                            mNetErrorLayout.setVisibility(View.GONE);
                            if (!ServerConnnectUtil.instance().isTradeConnect || !ServerConnnectUtil.instance().isQuoteConnect) {
                                if (DataManager.instance().getLoadDataState(GTSConst.ZONE_TYPE_ALL + "")) {
                                    mServerErrorTopView.setVisibility(View.VISIBLE);
                                }
                            }
                        } else {
                            if (!isTimeOut) {
                                cancelTask();
                                if (DataManager.instance().getLoadDataState(GTSConst.ZONE_TYPE_ALL + "")) {
                                    mNetErrorTopView.setVisibility(View.VISIBLE);
                                    mNetErrorLayout.setVisibility(View.GONE);
                                    mServerErrorTopView.setVisibility(View.GONE);
                                } else {
                                    mNetErrorTopView.setVisibility(View.GONE);
                                    mNetErrorLayout.setVisibility(View.VISIBLE);
                                    mServerErrorTopView.setVisibility(View.GONE);
                                }
                                mServerErrorView.setVisibility(View.GONE);
                            }
                            mProgress.setVisibility(View.GONE);
                        }
                    }
                });
        bindSubscription(netRegister);

        Disposable quoteAllRegister = RxBus.getInstance().registertoObservableSticky(GTSConst.REPLY_SYMBOL_ALLLIST + "", Bundle.class).observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<Bundle>() {

                    @Override
                    public void accept(@NonNull Bundle bundle) throws Exception {
                        onProgressVisible(false);
                        setClickView();
                        isTimeOut = false;
                        cancelTask();
                        requestCpsSwitch();
                        mNetErrorTopView.setVisibility(View.GONE);
                        mNetErrorLayout.setVisibility(View.GONE);
                        mServerErrorView.setVisibility(View.GONE);
                    }
                });
        bindSubscription(quoteAllRegister);

        Disposable accountRegister = RxBus.getInstance().registertoObservableSticky(GTSConst.REPLY_ACCOUNT_UPDATE + "", DataItemDetail.class).observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<DataItemDetail>() {

                    @Override
                    public void accept(@NonNull DataItemDetail account) throws Exception {
                        onAccountNotify();
                    }
                });
        bindSubscription(accountRegister);

        //并且，自选改变之后，要发送通知给这个Fragment，改变这个按钮的状态
        Disposable editBtnRegister = RxBus.getInstance().registertoObservableSticky(GTSConst.REPLY_SWITCH_QUOTE_EDIT_BTN + "", Boolean.class).observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<Boolean>() {

                    @Override
                    public void accept(@NonNull Boolean account) throws Exception {//那么，自选列表改变的回调在哪里呢
                        Log.d("dispatchEditBtn", "收到消息");
                        dispatchEditBtnByPosition(mCurrentPosition);
                    }
                });
        bindSubscription(editBtnRegister);
    }

    /**
     * 设置顶部按钮是否可以点击
     */
    private void setClickView() {
        if (DataManager.instance().getLoadDataState(GTSConst.ZONE_TYPE_ALL + "")) {
            mTitleBar.mLeftIcon.setClickable(true);
            mTitleBar.mRightIcon.setClickable(true);
        } else {
            mTitleBar.mLeftIcon.setClickable(false);
            mTitleBar.mRightIcon.setClickable(false);
        }
    }

    public Timer timer = new Timer();
    public TimerTask task;
    protected boolean isTimeOut = false;

    /**
     * 初始化定时任务(处理超时)
     */
    public void initTimerTask() {
        try {
            isTimeOut = false;
            Logger.e("NewQuoteFragment 初始化定时器 is ");
            // 初始化定时器
            task = new TimerTask() {
                @Override
                public void run() {
                    handler.sendEmptyMessage(AppContances.HANDLER_TIME_OUT);
                }
            };
            // 启动定时器,设定时间内如果没有响应,则提示超时信息
            timer.schedule(task, AppContances.SERVER_TIME_OUT);
        } catch (Exception e) {
            Logger.e("初始化定时任务异常！", e);
        }
    }

    /**
     * 取消超时定时
     */
    public void cancelTask() {
        if (null != task) {
            task.cancel();
            task = null;
        }
    }

    public Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            try {
                switch (msg.what) {
                    case AppContances.HANDLER_TIME_OUT:
                        Logger.e("NewQuoteFragment 服务器加载数据超时！");
                        isTimeOut = true;
                        cancelTask();
                        if (!DataManager.instance().getLoadDataState(GTSConst.ZONE_TYPE_ALL + "")) {
                            mServerErrorView.setVisibility(View.VISIBLE);
                            mNetErrorTopView.setVisibility(View.GONE);
                            mNetErrorLayout.setVisibility(View.GONE);
                            mProgress.setVisibility(View.GONE);
                        } else {
                            mServerErrorView.setVisibility(View.GONE);
                        }
                        break;
                }
            } catch (Exception e) {
                Logger.e("服务器加载数据异常！", e);
            }

        }
    };

    /**
     * 显示隐藏加载圈
     */
    public void onProgressVisible(Boolean isVisible) {
        if (null != mProgress) {
            Logger.e("NewQuoteFragment progress is " + isVisible);
            if (isVisible) {
                if (null == task && !DataManager.instance().getLoadDataState(GTSConst.ZONE_TYPE_ALL + "")) {
                    initTimerTask();
                }
                if (!isTimeOut) {
                    mProgress.setVisibility(View.VISIBLE);
                    mNetErrorTopView.setVisibility(View.GONE);
                    mNetErrorLayout.setVisibility(View.GONE);
                    mServerErrorView.setVisibility(View.GONE);
                    if (!ServerConnnectUtil.instance().isTradeConnect || !ServerConnnectUtil.instance().isQuoteConnect) {
                        if (DataManager.instance().getLoadDataState(GTSConst.ZONE_TYPE_ALL + "")) {
                            mServerErrorTopView.setVisibility(View.VISIBLE);
                        }
                    }
                }
            } else {
                if (DataManager.instance().getLoadDataState(GTSConst.ZONE_TYPE_ALL + "") || !NetworkMonitor.hasNetWorkNoToast()) {
                    mProgress.setVisibility(View.GONE);
                } else {
                    if (!isTimeOut) {
                        mProgress.setVisibility(View.VISIBLE);
                    }
//                    else{
//                        mServerErrorView.setVisibility(View.VISIBLE);
//                    }
                }
            }
        } else {
            Logger.e("NewQuoteFragment progress is null");
        }
    }

    @Override
    public void onSendQuote() {
        if (null != mCurrentFragment) {
            mCurrentFragment.onSendQuote();
        }
    }

    @Override
    public void onHiddenChanged(boolean hidden) {
        super.onHiddenChanged(hidden);
        if (!hidden) {
            BaseActivity activity = (BaseActivity) getActivity();
            if (null != activity) {
                activity.setTransparentBar(false);
            }
        }
        if (null != mCurrentFragment && mCurrentFragment.isResumed()) {
            mCurrentFragment.onHiddenChanged(hidden);
        }
        onAccountNotify();
    }

    @Override
    public void quoteServerNotice(Boolean isConntion) {
        if (isConntion) {
            ServerConnnectUtil.instance().cancelTask(true);
            if (isVisible() && null != mCurrentFragment && mCurrentFragment.isResumed()) {
                mCurrentFragment.onSendQuote();
            }
            if (ServerConnnectUtil.instance().isTradeConnect) {
                mServerErrorTopView.setVisibility(View.GONE);
            }
        } else {
            if (DataManager.instance().getLoadDataState(GTSConst.ZONE_TYPE_ALL + "") && NetworkMonitor.hasNetWork()) {
                mServerErrorTopView.setVisibility(View.VISIBLE);
            }
        }
    }

    @Override
    public void onRequestSuc(Object result) {
        if (!isVisible()) {
            return;
        }
        MainActivity mainActivity = (MainActivity) getActivity();
        if (mainActivity != null) {
            mainActivity.hideLoading();
            mainActivity.removeAllFragment(true, false);
        } else {
            Logger.e("切换账号 getActivity() is null");
        }
        AppTerminal.instance().setLoginView(0);
        if (null != mSwitchPresenter) {
            mSwitchPresenter.clearData();
            mSwitchPresenter = null;
        }
    }

    @Override
    public void onRequestFail(int failCode) {
        final BaseActivity mActivity = (BaseActivity) getActivity();
        if (null != mActivity) {
            mActivity.hideLoading();
            if (failCode == 1 || failCode == 34) {
                return;
            }
            String error;
            if (failCode >= 1100 && failCode < 1200) {
                error = ConfigUtil.instance().getErrorConfigObject().optString(ConfigType.SERVER_ERROR_1100) + failCode;
            } else {
                error = ConfigUtil.instance().getErrorConfigObject().optString(failCode + "");
            }
            PopupConfirmDialog dialog = PopupConfirmDialog.newInstance(mActivity, error, new BtnClickListener() {
                @Override
                public void onBtnClick(int viewID) {
                    GTConfig.instance().isPhoneLogin = false;
                    GTConfig.instance().mCurLoginPhone = "";
                    ActivityManager.backLogin(mActivity, true);
                }
            });
            dialog.setCancelable(false);
            dialog.show();
        }
        if (GTConfig.instance().getBooleanValue(GTConfig.PREF_AUTO_LOGIN)) {
            GTConfig.instance().setBooleanValue(GTConfig.PREF_AUTO_LOGIN, false);
        }
        GTConfig.instance().mUserPwd = "";
        if (null != mSwitchPresenter) {
            mSwitchPresenter.clearData();
            mSwitchPresenter = null;
        }
    }

    @Override
    public void tradeServerNotice(Boolean isConntion) {
        if (isConntion) {
            if (ServerConnnectUtil.instance().isQuoteConnect) {
                mServerErrorTopView.setVisibility(View.GONE);
            }
        } else {
            if (DataManager.instance().getLoadDataState(GTSConst.ZONE_TYPE_ALL + "") && NetworkMonitor.hasNetWork()) {
                mServerErrorTopView.setVisibility(View.VISIBLE);
            }
        }
    }

    @OnClick(R.id.quote_bottom_login)
    void createAccount() {
        if (CommonUtils.isFastDoubleClick()) {
            return;
        }
        PackStatis.getToService(PackStatis.EventAction.CLICKREG.getValue(), PackStatis.EventCategory.HOME.getValue(), null, null);
        //ActivityManager.showOpenAccount(getActivity(), ConfigType.ADD_LOGIN_REAL_TAG);
        GTConfig.instance().setAccountType(GTConfig.ACC_TYPE_REAL);
        ActivityManager.backLogin(getActivity(), false);
    }

    @OnClick(R.id.quote_bottom_bar)
    void onLoginLayout() {
        //do nothing
        // 拦截点击事件
    }

    private View welfareView; // 新手福利弹窗小广告

    /**
     * 新手福利小弹窗的广告哇
     */
    public void showNoviceWelfare(final String title, final String link) {
        View mRootView = getView();
        if (mRootView != null && welfareView == null && (mRootView instanceof RelativeLayout)) {
            welfareView = NoviceWelfarePresenter.getInstance().createView(getActivity(), title, link);
            RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            params.addRule(RelativeLayout.CENTER_HORIZONTAL);
            params.topMargin = DeviceUtil.instance().dip2px(130, AppMain.getApp());
            ((RelativeLayout) mRootView).addView(welfareView, params);
        }
    }

    public void hideNoviceWelfare() {
        if (welfareView != null) {
            AnimatorSet set = (AnimatorSet) welfareView.getTag();
            if (set != null) {
                set.cancel();
            }
            welfareView.setTag(null);
            ViewGroup parent = (ViewGroup) welfareView.getParent();
            if (parent != null) {
                parent.removeView(welfareView);
                welfareView = null;
            }
        }
    }

}
